package meijuli.com.join51.business.app

import android.annotation.TargetApi
import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Build
import android.support.multidex.MultiDex
import cn.jpush.android.api.JPushInterface
import com.jhx.common.app.CommonModule
import com.jhx.common.thirdparty.db.DBHelper
import com.jhx.video.module.VideoModule
import com.tencent.bugly.beta.Beta
import com.tencent.tinker.loader.app.DefaultApplicationLike
import meijuli.com.join51.business.thirdparty.bugly.TencentBugly

/**
 * 热修复配置
 *
 * @author Wizong 2017-05-19 13:09
 */
class HotFixApplicationLike(application: Application,
                            tinkerFlags: Int,
                            tinkerLoadVerifyFlag: Boolean,
                            applicationStartElapsedTime: Long,
                            applicationStartMillisTime: Long,
                            tinkerResultIntent: Intent) :
        DefaultApplicationLike(application,
                               tinkerFlags,
                               tinkerLoadVerifyFlag,
                               applicationStartElapsedTime,
                               applicationStartMillisTime,
                               tinkerResultIntent) {

    override fun onCreate() {
        super.onCreate()
        init()
    }

    private fun init() {
        // 必须先初始化后再设置debug值，CommonModule初始化必须在其他之前
        CommonModule.init(application)
        CommonModule.debug(true)
        TencentBugly.init(application)
        JPushInterface.setDebugMode(true)
        JPushInterface.init(application)
        VideoModule.init(application)
        DBHelper.init(application)
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    override fun onBaseContextAttached(base: Context?) {
        super.onBaseContextAttached(base)
        MultiDex.install(base)

        // 安装tinker
        Beta.installTinker(this)
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    fun registerActivityLifecycleCallback(callbacks: android.app.Application.ActivityLifecycleCallbacks) {
        application.registerActivityLifecycleCallbacks(callbacks)
    }
}